import fastJson from 'fast-json-stringify'
import proto from './messageProto'

const stringify = fastJson({
    title: 'message',
    type: 'object',
    properties: proto
})

export function serialize(key, params) {
    if (proto[key] == undefined) {
        console.error("协议不存在:" + key);
        return ""
    }
    const tempObject = {};
    tempObject[key] = params
    return stringify(tempObject);
}

export function deserialization(key, params) {
    if (proto[key] == undefined) {
        console.error("协议不存在:" + key);
        return ""
    }
    const tempObject = {};
    tempObject[key] = {}
    if (params === "") {
        return JSON.parse(stringify(tempObject))[key]
    }
    return Object.assign(JSON.parse(stringify(tempObject))[key], JSON.parse(params))
}



